#define __main_c

#include    "includeAll.h"

	
void main()
{


	ChangeToFastClk();
	P1MODH=0x00;
	P3MODL=0x00;
	P3MODH=0x00;
   EA=1;
ET0=1;
TR0=1;
	TMOD=0x11;
		TH2 = (65536-450)/256;   //0.25ms==4khz timer2 interrupt
    RCP2H = TH2  ;
    TL2 = (65536-450)%256;
    RCP2L = TL2  ;
    ET2 = 1;            //timer2 interrupt enable
    TR2 = 1;            //timer2 running
		Buzz();

	while(1){
		GetKey();

		switch (keyValue)
        {
            case 1:
            Buzz();
						
            break;
						case 2:
            Buzz();
            break;
						case 3:
            Buzz();
            break;
					  case 4:
            Buzz();
            break;
						case 5:
            Buzz();
            break;
						
        }
				keyValue=0;
		}
}
	void InterruptTimer2() interrupt 5
{
    TF2 = 0;			//clear interrupt flag
    TR2 = 1;
	  if(buzzLastTimer > 0){
	
        F_buzz() ;
    }}

void InterruptTimer0() interrupt 1
{
    	TH0=(65536-14745)/256;
        TL0=(65536-14745)%256;
     
	if(buzzLastTimer > 0){
		buzzLastTimer-- ;
	}		
    KeyJudge();

}

void ChangeToFastClk(void)
{
	CLKCON = 0x03;	//Clock div 1
	STPPCK = 0;
	STPFCK = 0;	
	_nop_();	
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	SELFCK = 1;
}
/* void Delay()
{
	hwTimer = 0xffff ; 
    while(hwTimer--){
	    CLRWDT = 1;			//clear watchdog 
		CLRWDT = 1;	
		CLRWDT = 1;	
		CLRWDT = 1;			//clear watchdog 
		CLRWDT = 1;	
		CLRWDT = 1;
	}
} */